<?php

namespace IDock\Insurance\ZYIC\Response;

use IDock\Http\Response;
use IDock\Insurance\ZYIC\Response\AllZYICResponse;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;
use IDock\Printer\UnderwritingRecallPrinter;

class NonCarUnderwritingResponse extends AllZYICResponse
{

    public function resolve(): Response
    {
        $body = $this->getBody();
        if (!json_decode($body)) {
            $this->setError('返回数据异常');
            return  $this;
        }
        $data = json_decode($body,true);
        if ($this->printer and  is_string($this->printer)) {
            $this->printer = new $this->printer;
        }

        $resultCode = $data['status'] ?? '';
        $resultMess = $data['message'] ?? '';

        if($resultCode != 200) {
            $this->setError($resultMess);
            return $this;
        }
        $this->setBody($data);

        return $this;
    }

    public function printerInit(): Response
    {
        $body = $this->getBody();
        $code = $body['msgCode'] ?? '';
        if($code != '0' && ($body['msgInfo'] ?? '') != '该渠道订单号已有出单记录'){
            $this->setError($body['msgInfo'] ?? '');
            return $this;
        }
        $printer = new NonCarProductListPrinter();


        $this->printer = $printer;
        return $this;
    }
}
